/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { BaseMatcher } from '../BaseMatcher.js';
export class HasProperty extends BaseMatcher {
    constructor(propertyName) {
        super();
        this.propertyName = propertyName;
    }
    matches(obj) {
        return obj == null ? false : this.hasOwn(obj, this.propertyName);
    }
    describeMismatch(item, mismatchDescription) {
        mismatchDescription.appendText("no ").appendValue(this.propertyName).appendText(" in ").appendValue(item);
    }
    describeTo(description) {
        description.appendText("hasProperty(").appendValue(this.propertyName).appendText(")");
    }
    /**
     * Creates a matcher that matches when the examined object has a JavaBean property
     * with the specified name.
     * For example:
     * <pre>assertThat(myBean, hasProperty("foo"))</pre>
     *
     * @param <T>
     *     the matcher type.
     * @param propertyName
     *     the name of the JavaBean property that examined beans should possess
     * @return The matcher.
     */
    static hasProperty(propertyName) {
        return new HasProperty(propertyName);
    }
    hasOwn(obj, value) {
        for (let key in obj) {
            if (key === value) {
                return true;
            }
        }
        return false;
    }
}
